package com.zhisheng.day10_tlias.entry;

import java.io.Serializable;

// 通用返回结果类
public class R<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    // 状态码
    private int code;
    // 消息
    private String msg;
    // 数据
    private T data;

    public R() {
    }

    public R(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public R(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    // 成功返回
    public static <T> R<T> success(T data) {
        return new R<>(1, "操作成功", data);
    }

    // 失败返回
    public static <T> R<T> fail(String msg) {
        return new R<>(0, msg, null);
    }

    // Getter 和 Setter 方法
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}